package com.dianrui.fmi.fragment;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.dianrui.fmi.R;
import com.dianrui.fmi.activity.EditStockActivity;
import com.dianrui.fmi.activity.KLineActivity;
import com.dianrui.fmi.activity.SearchActivity;
import com.dianrui.fmi.adapter.MarketAdapter;
import com.dianrui.fmi.adapter.QuotesAdapter;
import com.dianrui.fmi.bean.Market;
import com.dianrui.fmi.bean.Qutos;
import com.dianrui.fmi.event.AddOptionalStock;
import com.dianrui.fmi.event.RfreshQutoes;
import com.dianrui.fmi.event.SwitchAccount;
import com.dianrui.fmi.util.CountDownTimerUtils;
import com.dianrui.fmi.util.OkHttpUtils;
import com.dianrui.fmi.util.StringUtils;
import com.dianrui.fmi.util.Url;
import com.google.gson.JsonObject;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;

public class QutoesFragment extends BaseFragment {
    private ProgressDialog pd;
    private String type;
    private List<String> symbolList = new ArrayList<>();
    private List<Qutos> mQutoList = new ArrayList<>();
    private List<Market> mQutoMarketList = new ArrayList<>();
    private QuotesAdapter quotesAdapter;
    private MarketAdapter marketAdapter;

    @BindView(R.id.forex_txt1)
    TextView forexTxt1;
    @BindView(R.id.quotes_commoities_txt1)
    TextView quotesCommoitiesTxt1;
    @BindView(R.id.main_shop_line1)
    View mainShopLine1;
    @BindView(R.id.optional_btn)
    Button optionalBtn;
    @BindView(R.id.market_btn)
    Button marketBtn;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.right_img)
    ImageView rightImg;
    @BindView(R.id.main_all_line)
    View mainAllLine;
    @BindView(R.id.main_all_line1)
    View mainAllLine1;
    @BindView(R.id.forex_txt)
    TextView forexTxt;
    @BindView(R.id.quotes_commoities_txt)
    TextView quotesCommoitiesTxt;
    @BindView(R.id.main_shop_line)
    View mainShopLine;
    @BindView(R.id.quotes_list)
    ListView quotesList;
    @BindView(R.id.market_list)
    ListView marketList;
    @BindView(R.id.edit_stuck)
    LinearLayout editStuck;
    @BindView(R.id.optional_layout)
    LinearLayout optionalLayout;
    @BindView(R.id.marker_show_layout)
    LinearLayout markerShowLayout;

    @BindView(R.id.trading)
    Button trading;


    @BindView(R.id.quote_emptyView)
    LinearLayout quoteEmptyView;


    @Override
    public int getContentViewId() {
        return R.layout.frag_quotes;
    }

    @Override
    public void initView() {
        pd=new ProgressDialog(getActivity());
        EventBus.getDefault().register(this);
        title.setText(getString(R.string.main_quotes_txt));
        rightImg.setVisibility(View.VISIBLE);
        quotesAdapter = new QuotesAdapter(getActivity(), mQutoList);
        quotesList.setAdapter(quotesAdapter);
        type = "0";
        getQutosList("2");
        quotesAdapter.setOnButtonClickListener(new QuotesAdapter.QuotesClickListener() {
            @Override
            public void onRegularClick(long tick, String name, String symbold, String type, String symbol, String fullsymbol, String price, String high, String low, String open, String zf, String yc, String buy1, String buy2, String position, String servicecharge, String zc) {
                Intent intent = new Intent(getActivity(), KLineActivity.class);
                Bundle bundle = new Bundle();
                bundle.putLong("tick", tick);
                bundle.putString("symbold", symbold);
                bundle.putString("name", name);
                bundle.putString("type", type);
                bundle.putString("symbol", symbol);
                bundle.putString("open", open);
                bundle.putString("high", high);
                bundle.putString("low", low);
                bundle.putString("fullsymbol", fullsymbol);
                bundle.putString("price", price);
                bundle.putString("zf", zf);
                bundle.putString("type", "1");
                bundle.putString("zc", zc);
                bundle.putString("yc", yc);
                bundle.putString("buy1", buy1);
                bundle.putString("buy2", buy2);
                bundle.putString("position", position);
                bundle.putString("servicecharge", servicecharge);
                intent.putExtras(bundle);
                startActivity(intent);
            }

        });
        if (detailsTimer != null) {
            detailsTimer.start();
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(RfreshQutoes rfreshQutoes) {
        type="2";
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                getQutosList("2");
            }
        },1000);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(AddOptionalStock addOptionalStock) {
        type="2";
        forexTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.orange));
        quotesCommoitiesTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_333333));
        mainAllLine.setVisibility(View.VISIBLE);
        mainShopLine.setVisibility(View.INVISIBLE);
        trading.setVisibility(View.GONE);
        editStuck.setVisibility(View.VISIBLE);
        optionalLayout.setVisibility(View.VISIBLE);
        quotesList.setVisibility(View.VISIBLE);
        marketList.setVisibility(View.GONE);
        markerShowLayout.setVisibility(View.GONE);
        optionalBtn.setBackgroundResource(R.drawable.orange_shape);
        marketBtn.setBackgroundResource(R.drawable.white_shape);
        optionalBtn.setTextColor(Color.WHITE);
        marketBtn.setTextColor(getActivity().getResources().getColor(R.color.gray_ff686c6f));
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                getQutosList("2");
            }
        },1000);

    }


    CountDownTimerUtils detailsTimer = new CountDownTimerUtils(Long.MAX_VALUE, 6000) {
        @Override
        public void onTick(long millisUntilFinished) {
            switch (type) {
                case "0":
                    getTimerQutosList("2");
                    break;
                case "1":
                    getTimerMarketList("2");
                    break;


                case "2":
                    getTimerQutosList("2");
                    break;
                case "3":
                    getTimerQutosList("3");
                    break;


                case "4":
                    getTimerMarketList("2");
                    break;

                case "5":
                    getTimerMarketList("3");
                    break;

                    default:
                        break;
            }
        }

        @Override
        public void onFinish() {}
    };


    private void getQutosList(String type) {
        pd.show();
        pd.setMessage(getString(R.string.load));
        pd.setCanceledOnTouchOutside(false);
        pd.setCancelable(false);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("type", type);
        jsonObject.addProperty("optional", "1");
        jsonObject.addProperty("index", "0");
        OkHttpUtils.getInstance().postWithMemberToken(Url.QUOTES_LIST, jsonObject.toString(), new OkHttpUtils.XCallBack() {
            @Override
            public void onResponse(String result) {
                if (!StringUtils.isEmpty(result)) {
                    try {
                        final JSONObject jsonObject = new JSONObject(result);
                        if (null != jsonObject) {
                            if ("1000".equals(jsonObject.optString("status"))) {
                                pd.dismiss();
                                if (mQutoList != null) {
                                    mQutoList.clear();
                                }
                                JSONArray jsonArray = jsonObject.optJSONArray("data");
                                if (jsonArray.length() > 0) {
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        Qutos Qutos = new Qutos();
                                        Qutos.symbols_id = jsonArray.optJSONObject(i).optString("symbols_id");
                                        Qutos.full_symbol = jsonArray.optJSONObject(i).optString("full_symbol");
                                        Qutos.symbol = jsonArray.optJSONObject(i).optString("symbol");
                                        Qutos.name = jsonArray.optJSONObject(i).optString("name");
                                        Qutos.type = jsonArray.optJSONObject(i).optString("type");
                                        Qutos.market = jsonArray.optJSONObject(i).optString("market");
                                        Qutos.tick = jsonArray.optJSONObject(i).optLong("tick");
                                        Qutos.i = jsonArray.optJSONObject(i).optString("i");
                                        Qutos.itd = jsonArray.optJSONObject(i).optString("itd");
                                        Qutos.price = jsonArray.optJSONObject(i).optString("price");
                                        Qutos.o = jsonArray.optJSONObject(i).optString("o");
                                        Qutos.h = jsonArray.optJSONObject(i).optString("h");
                                        Qutos.l = jsonArray.optJSONObject(i).optString("l");
                                        Qutos.yc = jsonArray.optJSONObject(i).optString("yc");
                                        Qutos.v = jsonArray.optJSONObject(i).optString("v");
                                        Qutos.zf = jsonArray.optJSONObject(i).optString("zf");
                                        Qutos.zd = jsonArray.optJSONObject(i).optString("zd");
                                        Qutos.buy1 = jsonArray.optJSONObject(i).optString("buy1");
                                        Qutos.buy2 = jsonArray.optJSONObject(i).optString("buy2");
                                        Qutos.position = jsonArray.optJSONObject(i).optString("position");
                                        Qutos.service_charge = jsonArray.optJSONObject(i).optString("service_charge");
                                        mQutoList.add(Qutos);
                                    }
                                    if (quotesAdapter != null) {
                                        quotesAdapter.refresh(mQutoList);
                                    }
                                    quotesList.setVisibility(View.VISIBLE);
                                    marketList.setVisibility(View.GONE);
                                    quoteEmptyView.setVisibility(View.GONE);

                                }else {
                                    pd.dismiss();
                                    quotesList.setVisibility(View.GONE);
                                    marketList.setVisibility(View.GONE);
                                    quoteEmptyView.setVisibility(View.VISIBLE);
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }else {
                    pd.dismiss();
                }
            }
        });
    }

    private void getTimerQutosList(String type) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("type", type);
        jsonObject.addProperty("optional", "1");
        jsonObject.addProperty("index", "0");
        OkHttpUtils.getInstance().postWithMemberToken(Url.QUOTES_LIST, jsonObject.toString(), new OkHttpUtils.XCallBack() {
            @Override
            public void onResponse(String result) {
                if (!StringUtils.isEmpty(result)) {
                    try {
                        final JSONObject jsonObject = new JSONObject(result);
                        if (null != jsonObject && isAdded()) {
                            if ("1000".equals(jsonObject.optString("status"))) {
                                if (mQutoList != null) {
                                    mQutoList.clear();
                                }
                                JSONArray jsonArray = jsonObject.optJSONArray("data");
                                if (jsonArray.length() > 0) {
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        Qutos Qutos = new Qutos();
                                        Qutos.symbols_id = jsonArray.optJSONObject(i).optString("symbols_id");
                                        Qutos.full_symbol = jsonArray.optJSONObject(i).optString("full_symbol");
                                        Qutos.symbol = jsonArray.optJSONObject(i).optString("symbol");
                                        Qutos.name = jsonArray.optJSONObject(i).optString("name");
                                        Qutos.type = jsonArray.optJSONObject(i).optString("type");
                                        Qutos.market = jsonArray.optJSONObject(i).optString("market");
                                        Qutos.tick = jsonArray.optJSONObject(i).optLong("tick");
                                        Qutos.i = jsonArray.optJSONObject(i).optString("i");
                                        Qutos.itd = jsonArray.optJSONObject(i).optString("itd");
                                        Qutos.price = jsonArray.optJSONObject(i).optString("price");
                                        Qutos.o = jsonArray.optJSONObject(i).optString("o");
                                        Qutos.h = jsonArray.optJSONObject(i).optString("h");
                                        Qutos.l = jsonArray.optJSONObject(i).optString("l");
                                        Qutos.yc = jsonArray.optJSONObject(i).optString("yc");
                                        Qutos.v = jsonArray.optJSONObject(i).optString("v");
                                        Qutos.zf = jsonArray.optJSONObject(i).optString("zf");
                                        Qutos.zd = jsonArray.optJSONObject(i).optString("zd");
                                        Qutos.buy1 = jsonArray.optJSONObject(i).optString("buy1");
                                        Qutos.buy2 = jsonArray.optJSONObject(i).optString("buy2");
                                        Qutos.position = jsonArray.optJSONObject(i).optString("position");
                                        Qutos.service_charge = jsonArray.optJSONObject(i).optString("service_charge");
                                        mQutoList.add(Qutos);
                                    }
                                    if (quotesAdapter != null) {
                                        quotesAdapter.refresh(mQutoList);
                                    }
                                    quotesList.setVisibility(View.VISIBLE);
                                    marketList.setVisibility(View.GONE);
                                    quoteEmptyView.setVisibility(View.GONE);

                                }else {
                                    pd.dismiss();
                                    quotesList.setVisibility(View.GONE);
                                    marketList.setVisibility(View.GONE);
                                    quoteEmptyView.setVisibility(View.VISIBLE);
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }else {
                    pd.dismiss();
                }
            }
        });
    }


    private void getMarketList(String type) {
        pd.show();
        pd.setCanceledOnTouchOutside(false);
        pd.setCancelable(false);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("type", type);
        jsonObject.addProperty("optional", "0");
        jsonObject.addProperty("index", "0");
        OkHttpUtils.getInstance().postWithMemberToken(Url.QUOTES_LIST, jsonObject.toString(), new OkHttpUtils.XCallBack() {
            @Override
            public void onResponse(String result) {
                if (!StringUtils.isEmpty(result)) {
                    try {
                        final JSONObject jsonObject = new JSONObject(result);
                        if (null != jsonObject && isAdded()) {
                            if ("1000".equals(jsonObject.optString("status"))) {
                                pd.dismiss();
                                if (mQutoMarketList != null) {
                                    mQutoMarketList.clear();
                                }
                                JSONArray jsonArray = jsonObject.optJSONArray("data");
                                if (jsonArray.length() > 0) {
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        Market market = new Market();
                                        market.symbols_id = jsonArray.optJSONObject(i).optString("symbols_id");
                                        market.full_symbol = jsonArray.optJSONObject(i).optString("full_symbol");
                                        market.symbol = jsonArray.optJSONObject(i).optString("symbol");
                                        market.name = jsonArray.optJSONObject(i).optString("name");
                                        market.type = jsonArray.optJSONObject(i).optString("type");
                                        market.market = jsonArray.optJSONObject(i).optString("market");
                                        market.tick = jsonArray.optJSONObject(i).optLong("tick");
                                        market.i = jsonArray.optJSONObject(i).optString("i");
                                        market.itd = jsonArray.optJSONObject(i).optString("itd");
                                        market.price = jsonArray.optJSONObject(i).optString("price");
                                        market.o = jsonArray.optJSONObject(i).optString("o");
                                        market.h = jsonArray.optJSONObject(i).optString("h");
                                        market.l = jsonArray.optJSONObject(i).optString("l");
                                        market.yc = jsonArray.optJSONObject(i).optString("yc");
                                        market.v = jsonArray.optJSONObject(i).optString("v");
                                        market.zf = jsonArray.optJSONObject(i).optString("zf");
                                        market.zd = jsonArray.optJSONObject(i).optString("zd");
                                        market.buy1 = jsonArray.optJSONObject(i).optString("buy1");
                                        market.buy2 = jsonArray.optJSONObject(i).optString("buy2");
                                        market.position = jsonArray.optJSONObject(i).optString("position");
                                        market.service_charge = jsonArray.optJSONObject(i).optString("service_charge");
                                        mQutoMarketList.add(market);
                                    }
                                    if (marketAdapter != null) {
                                        marketAdapter.refresh(mQutoMarketList);
                                    }
                                    quotesList.setVisibility(View.GONE);
                                    marketList.setVisibility(View.VISIBLE);
                                    quoteEmptyView.setVisibility(View.GONE);

                                }else {
                                    pd.dismiss();
                                    marketList.setVisibility(View.GONE);
                                    quotesList.setVisibility(View.GONE);
                                    quoteEmptyView.setVisibility(View.VISIBLE);
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }else{
                    pd.dismiss();
                }
            }
        });
    }




    private void getTimerMarketList(String type) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("type", type);
        jsonObject.addProperty("optional", "0");
        jsonObject.addProperty("index", "0");
        OkHttpUtils.getInstance().postWithMemberToken(Url.QUOTES_LIST, jsonObject.toString(), new OkHttpUtils.XCallBack() {
            @Override
            public void onResponse(String result) {
                if (!StringUtils.isEmpty(result)) {
                    try {
                        final JSONObject jsonObject = new JSONObject(result);
                        if (null != jsonObject && isAdded()) {
                            if ("1000".equals(jsonObject.optString("status"))) {
                                if (mQutoMarketList != null) {
                                    mQutoMarketList.clear();
                                }
                                JSONArray jsonArray = jsonObject.optJSONArray("data");
                                if (jsonArray.length() > 0) {
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        Market market = new Market();
                                        market.symbols_id = jsonArray.optJSONObject(i).optString("symbols_id");
                                        market.full_symbol = jsonArray.optJSONObject(i).optString("full_symbol");
                                        market.symbol = jsonArray.optJSONObject(i).optString("symbol");
                                        market.name = jsonArray.optJSONObject(i).optString("name");
                                        market.type = jsonArray.optJSONObject(i).optString("type");
                                        market.market = jsonArray.optJSONObject(i).optString("market");
                                        market.tick = jsonArray.optJSONObject(i).optLong("tick");
                                        market.i = jsonArray.optJSONObject(i).optString("i");
                                        market.itd = jsonArray.optJSONObject(i).optString("itd");
                                        market.price = jsonArray.optJSONObject(i).optString("price");
                                        market.o = jsonArray.optJSONObject(i).optString("o");
                                        market.h = jsonArray.optJSONObject(i).optString("h");
                                        market.l = jsonArray.optJSONObject(i).optString("l");
                                        market.yc = jsonArray.optJSONObject(i).optString("yc");
                                        market.v = jsonArray.optJSONObject(i).optString("v");
                                        market.zf = jsonArray.optJSONObject(i).optString("zf");
                                        market.zd = jsonArray.optJSONObject(i).optString("zd");
                                        market.buy1 = jsonArray.optJSONObject(i).optString("buy1");
                                        market.buy2 = jsonArray.optJSONObject(i).optString("buy2");
                                        market.position = jsonArray.optJSONObject(i).optString("position");
                                        market.service_charge = jsonArray.optJSONObject(i).optString("service_charge");
                                        mQutoMarketList.add(market);
                                    }
                                    if (marketAdapter != null) {
                                        marketAdapter.refresh(mQutoMarketList);
                                    }
                                    quotesList.setVisibility(View.GONE);
                                    marketList.setVisibility(View.VISIBLE);
                                    quoteEmptyView.setVisibility(View.GONE);

                                }else {

                                    marketList.setVisibility(View.GONE);
                                    quotesList.setVisibility(View.GONE);
                                    quoteEmptyView.setVisibility(View.VISIBLE);
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }else{
                    pd.dismiss();
                }
            }
        });
    }





    @Override
    public void getData() {}


    @OnClick({R.id.optional_layout, R.id.optional_btn, R.id.market_btn, R.id.right_img, R.id.trading,R.id.edit_stuck, R.id.forex_layout, R.id.quotes_commoities_layout,  R.id.forex_layout1, R.id.quotes_commoities_layout1})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.right_img:
                JumpActivitys(SearchActivity.class);
                break;
            case R.id.trading:
                EventBus.getDefault().post(new SwitchAccount());
                break;
            case R.id.optional_layout:
                break;

            case R.id.forex_layout:
                forexTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.orange));
                quotesCommoitiesTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_333333));
                mainAllLine.setVisibility(View.VISIBLE);
                mainShopLine.setVisibility(View.INVISIBLE);
                type = "2";
                getQutosList("2");
                break;

            case R.id.quotes_commoities_layout:
                forexTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_333333));
                quotesCommoitiesTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.orange));
                mainAllLine.setVisibility(View.INVISIBLE);
                mainShopLine.setVisibility(View.VISIBLE);
                type = "3";
                getQutosList("3");
                break;

            case R.id.forex_layout1://market
                forexTxt1.setTextColor(ContextCompat.getColor(getActivity(), R.color.orange));
                quotesCommoitiesTxt1.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_333333));
                mainAllLine1.setVisibility(View.VISIBLE);
                mainShopLine1.setVisibility(View.INVISIBLE);
                type = "4";
                getMarketList("2");
                break;
            case R.id.quotes_commoities_layout1://market
                forexTxt1.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_333333));
                quotesCommoitiesTxt1.setTextColor(ContextCompat.getColor(getActivity(), R.color.orange));
                mainAllLine1.setVisibility(View.INVISIBLE);
                mainShopLine1.setVisibility(View.VISIBLE);
                type = "5";
                getMarketList("3");
                break;

            case R.id.optional_btn:
                type="0";
                forexTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.orange));
                quotesCommoitiesTxt.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_333333));
                mainAllLine.setVisibility(View.VISIBLE);
                mainShopLine.setVisibility(View.INVISIBLE);
                trading.setVisibility(View.GONE);
                editStuck.setVisibility(View.VISIBLE);
                optionalLayout.setVisibility(View.VISIBLE);
                marketList.setVisibility(View.GONE);
                quotesList.setVisibility(View.VISIBLE);
                markerShowLayout.setVisibility(View.GONE);
                optionalBtn.setBackgroundResource(R.drawable.orange_shape);
                marketBtn.setBackgroundResource(R.drawable.white_shape);
                optionalBtn.setTextColor(Color.WHITE);
                marketBtn.setTextColor(getActivity().getResources().getColor(R.color.gray_ff686c6f));
                quotesAdapter = new QuotesAdapter(getActivity(), mQutoList);
                quotesList.setAdapter(quotesAdapter);
                getQutosList("2");
                quotesAdapter.setOnButtonClickListener(new QuotesAdapter.QuotesClickListener() {
                    @Override
                    public void onRegularClick(long tick, String name, String symbold, String type, String symbol, String fullsymbol, String price, String high, String low, String open, String zf, String yc, String buy1, String buy2, String position, String servicecharge, String zc) {
                        Intent intent = new Intent(getActivity(), KLineActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putLong("tick", tick);
                        bundle.putString("symbold", symbold);
                        bundle.putString("name", name);
                        bundle.putString("type", type);
                        bundle.putString("symbol", symbol);
                        bundle.putString("open", open);
                        bundle.putString("high", high);
                        bundle.putString("low", low);
                        bundle.putString("fullsymbol", fullsymbol);
                        bundle.putString("price", price);
                        bundle.putString("zf", zf);
                        bundle.putString("zc", zc);
                        bundle.putString("yc", yc);
                        bundle.putString("buy1", buy1);
                        bundle.putString("buy2", buy2);
                        bundle.putString("position", position);
                        bundle.putString("servicecharge", servicecharge);
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }

                });
                break;
            case R.id.market_btn:
                type="1";
                quotesList.setVisibility(View.GONE);
                marketList.setVisibility(View.VISIBLE);
                quoteEmptyView.setVisibility(View.GONE);
                trading.setVisibility(View.VISIBLE);
                optionalBtn.setBackgroundResource(R.drawable.white_shape);
                marketBtn.setBackgroundResource(R.drawable.orange_shape);
                optionalBtn.setTextColor(getActivity().getResources().getColor(R.color.gray_ff686c6f));
                forexTxt1.setTextColor(ContextCompat.getColor(getActivity(), R.color.orange));
                mainAllLine1.setVisibility(View.VISIBLE);
                quotesCommoitiesTxt1.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_333333));
                mainShopLine1.setVisibility(View.INVISIBLE);
                marketBtn.setTextColor(Color.WHITE);
                editStuck.setVisibility(View.GONE);
                optionalLayout.setVisibility(View.GONE);
                markerShowLayout.setVisibility(View.VISIBLE);
                marketAdapter = new MarketAdapter(getActivity(), mQutoMarketList);
                marketList.setAdapter(marketAdapter);
                getMarketList("2");
                marketAdapter.setOnButtonClickListener(new MarketAdapter.MarketQuotesClickListener() {
                    @Override
                    public void onMarketQuotesClick(long tick, String name, String symbold, String type, String symbol, String fullsymbol, String price, String high, String low, String open, String zf, String yc, String buy1, String buy2, String position, String servicecharge, String zc) {
                        Intent intent = new Intent(getActivity(), KLineActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putLong("tick", tick);
                        bundle.putString("symbold", symbold);
                        bundle.putString("name", name);
                        bundle.putString("type", type);
                        bundle.putString("symbol", symbol);
                        bundle.putString("open", open);
                        bundle.putString("high", high);
                        bundle.putString("low", low);
                        bundle.putString("fullsymbol", fullsymbol);
                        bundle.putString("price", price);
                        bundle.putString("zf", zf);
                        bundle.putString("zc", zc);
                        bundle.putString("yc", yc);
                        bundle.putString("type", "1");
                        bundle.putString("buy1", buy1);
                        bundle.putString("buy2", buy2);
                        bundle.putString("position", position);
                        bundle.putString("servicecharge", servicecharge);
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }



                });
                break;

            case R.id.edit_stuck:
                JumpActivitys(EditStockActivity.class);
                break;

            default:
                break;
        }
    }




    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        if (pd != null && pd.isShowing()) {
            pd.dismiss();
        }
        super.onDestroy();
    }
}
